package com.maben.server002;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 天气查询服务（进阶版）
 */
@WebService(targetNamespace = "http://webservice.maben.cn",
        serviceName = "weatherService",
        portName = "weatherServicePort",
        name = "weatherServiceInterface"
)
public class WeatherInterfaceImpl implements WeatherInterface {
    @Override
    @WebResult(name = "weatherResult")
    public List<WeatherModel> queryWeather(@WebParam(name="cityName") String cityName) {
        //构造三天的天气结果
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DATE);
        //第一天的天气
        WeatherModel weatherModel_1 = new WeatherModel();
        weatherModel_1.setDate(new Date());
        weatherModel_1.setDetail("晴朗");
        weatherModel_1.setTemperature_max(30);
        weatherModel_1.setTemperature_min(23);
        //第二天的天气
        WeatherModel weatherModel_2 = new WeatherModel();
        calendar.set(Calendar.DATE, day + 1);
        weatherModel_2.setDate(calendar.getTime());
        weatherModel_2.setDetail("晴转多云");
        weatherModel_2.setTemperature_max(28);
        weatherModel_2.setTemperature_min(21);
        //第三天的天气
        WeatherModel weatherModel_3 = new WeatherModel();
        calendar.set(Calendar.DATE, day + 2);
        weatherModel_3.setDate(calendar.getTime());
        weatherModel_3.setDetail("多云转小雨");
        weatherModel_3.setTemperature_max(25);
        weatherModel_3.setTemperature_min(18);

        List<WeatherModel> list = new ArrayList<WeatherModel>();
        list.add(weatherModel_1);
        list.add(weatherModel_2);
        list.add(weatherModel_3);
        //返回三天的天气
        return list;
    }

    public static void main(String[] args) {
        //发布WebService请求
        Endpoint.publish("http://localhost:2345/weather",new WeatherInterfaceImpl());
        System.out.println("发布server002成功");
    }
}
